﻿Public Class Form3

    Dim Eng As Integer
    Dim Math As Integer

    Private Sub btnEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnd.Click
        Application.Exit()
    End Sub

    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        Dim sum As Integer
        Dim avg As Double
        Dim WrongNumber As Boolean
        Try
            sum = CInt(txtEng.Text) + CInt(txtMath.Text)
            avg = sum / 2
            txtSum.Text = sum
            txtAvg.Text = avg.ToString("0.00")
        Catch ex As Exception
            WrongNumber = True
        End Try
        If WrongNumber OrElse Eng < 0 OrElse Eng > 100 Then
            ErrorProvider1.SetError(txtEng, "資料錯誤")
        End If


    End Sub

    Private Sub txtEng_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtEng.Validating

        Dim WrongNumber As Boolean

        Try
            Eng = CInt(txtEng.Text)
        Catch ex As Exception
            'MessageBox.Show(ex.ToString())
            WrongNumber = True
        End Try

        If WrongNumber OrElse Eng < 0 OrElse Eng > 100 Then
            ErrorProvider1.SetError(txtEng, "資料錯誤")
        Else
            ErrorProvider1.SetError(txtEng, "")
        End If

    End Sub

    
End Class